package com.limao.Admin.Servlet;

import java.io.IOException;

import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.limao.Model.LzPluginException;
import com.limao.Model.RecvData;
import com.limao.Tool.Function;
import com.limao.Utils.OutPrintClass;

@WebServlet(name="adminAjaxServlet", urlPatterns="/admin/adminAjaxServlet",asyncSupported=false)
public class adminAjaxServlet extends HttpServlet {

	private static final long serialVersionUID = -9122365659224071870L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub 
		this.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		HttpSession session = request.getSession();
		AsyncContext asyncContext=null;
		int m = -1;
		RecvData DataObj = null;
		Object reply = null;
		// 得到数据
		String StrData = OutPrintClass.readJSONString(request);
		if (StrData == null) {
			OutPrintClass.sendError(response, asyncContext, m, "出错，无数据");
			return ;
		}
		DataObj = JSON.parseObject(StrData, RecvData.class);
		if (DataObj == null) {
			OutPrintClass.sendError(response, asyncContext, m, "json解释出错");
			return ;
		}
		m = Integer.parseInt(DataObj.m);
		try {
			switch (m) 
			{
			case Function.Admin_AJAX_FOR_CITYLST: //取城市列表
				reply = AdminAjaxInfo.Admin_AJAX_FOR_CITYLST(session,response,asyncContext,m, DataObj);
				break;

			default:
				reply = OutPrintClass.errorObj(m,"出错，功能不存--adminAjaxServlet");
				
			}
		} catch (LzPluginException e) {
			reply = OutPrintClass.errorObj(m,e.getMessage());
		}
		
		OutPrintClass.writer(response, reply, asyncContext);
		
	}
	
}
